#!/usr/bin/env python
import cgi
import os
import wsgiref.handlers

from dataModels import *

from google.appengine.ext.webapp import template
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp

class Init(webapp.RequestHandler):
  def get(self):
    for a in HealthCondition.all():
      a.delete()
    bloodSugar = {
        'name':'High Blood Sugar',
        'cal':     2, 'satFat': 3,
        'transFat':3, 'choles': 1,
        'sodium':  3, 'fiber':  2,
        'sugar':   1, 'protien':3,
        }
    diab2 = {
        'name':'Type 2 Diabetes',
        'cal':3, 'satFat':2,
        'transFat':2, 'choles':2,
        'sodium':2, 'fiber':3,
        'sugar':1, 'protien':3,
        }
    highChol = {
        'name':'High Cholestrol',
        'cal':3, 'satFat':2,
        'transFat':2, 'choles':1,
        'sodium':2, 'fiber':3,
        'sugar':2, 'protien':2,
        }
    highBloodP = {
        'name':'High Blood Pressure',
        'cal':     3, 'satFat': 2,
        'transFat':2, 'choles': 1,
        'sodium':  2, 'fiber':  3,
        'sugar':   2, 'protien':3,
        }
    overweight = {
        'name':'Over Weight',
        'cal':     1, 'satFat': 2,
        'transFat':2, 'choles': 1,
        'sodium':  1, 'fiber':  3,
        'sugar':   1, 'protien':3,
        }
    HealthCondition(**bloodSugar).put()
    HealthCondition(**diab2).put()
    HealthCondition(**highChol).put()
    HealthCondition(**highBloodP).put()
    HealthCondition(**overweight).put()
    for i in MenuItem.all():
      i.delete()
    fin = open('menuItems.dat','r')
    for line in fin.readlines():
      name,cat,cost,cal,satFat,transFat,choles,sodium,fiber,sugar,protien = line.split()
      MenuItem(**{
        'name':name.replace('_',' '),'cat':int(cat),'cost':float(cost),'cal':int(cal),'satFat':int(satFat),
        'transFat':int(transFat),'choles':int(choles),'sodium':int(sodium),'fiber':int(fiber),
        'sugar':int(sugar),'protien':int(protien)
        }).put()
    fin.close()

class All(webapp.RequestHandler):
  def get(self):
    print 'admin.py All'
  def post(self):
    print 'admin.py All'

application = webapp.WSGIApplication([
  ('/admin/init',Init),
  ('.*',All),
], debug=True)

def main():
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
  main()
